package com.firstclass.service.impl;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.firstclass.dao.TaketeacherDao;
import com.firstclass.entity.TaketeacherEntity;
import com.firstclass.service.TaketeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("taketeacherService")
public class TaketeacherServiceImpl extends ServiceImpl<TaketeacherDao, TaketeacherEntity> implements TaketeacherService {

    @Autowired
    private TaketeacherDao taketeacherDao;

    @Override
    public List<TaketeacherEntity> queryByCondition(String name, String num, String subject) {
        final QueryWrapper<TaketeacherEntity> wrapper = new QueryWrapper<>();
        if (StrUtil.isNotBlank(name)) {
            wrapper.like("name", name);
        }
        if (StrUtil.isNotBlank(num)) {
            wrapper.like("num", num);
        }
        if (StrUtil.isNotBlank(subject)) {
            wrapper.like("subject", subject);
        }
        return this.list(wrapper);
    }

    @Override
    public boolean save(TaketeacherEntity taketeacherEntity) {
        if (taketeacherEntity.getId() == null) {
            taketeacherDao.insert(taketeacherEntity);
        } else {
            taketeacherDao.updateById(taketeacherEntity);
        }
        return true;
    }

}
